(function(jQuery) {
	jQuery.fn.paginaImpressao = function(pOptions) {
		var _defaultOptions = {
			form : {
				method	:	'post',
				target	:	'_blank',
				name	:	'formImpressao',
				template:	'<form name="{formName}" id="{formName}" action="{formAction}" method="{formMethod}" target="{formTarget}" style="display:none;>"' +
							'	<textarea name="{formName}_area" id="{formName}_area">{conteudo-area}</textarea>' +
							'	<textarea name="{formName}_data" id="{formName}_data">{conteudo-data}</textarea>' +
							'	<textarea name="{formName}_titulo" id="{formName}_titulo">{conteudo-titulo}</textarea>' +
							'	<textarea name="{formName}_chamada" id="{formName}_chamada">{conteudo-chamada}</textarea>' +
							'	<textarea name="{formName}_integra" id="{formName}_integra">{conteudo-integra}</textarea>' +
							'</form>'
			},
			action		:	'',
			area		:	'',
			data		:	'',
			titulo		:	'',
			chamada		:	'',
			integra 	:	'',
			href		:	( window.location.href + 'impressao/' )
		};
		
		var _options = jQuery.extend( _defaultOptions, pOptions );
		
		var _optionsToCheck = [ 'area', 'data', 'titulo', 'chamada', 'integra' ];
		for ( i = 0; i < _optionsToCheck.length; i++ ) {
			var _attr = jQuery( _options ).attr( _optionsToCheck[i] );
			if ( _attr == undefined ) {
				_attr = '';
			} else {
				if ( _attr == null ) {
					_attr = '';
				} else {
					_attr = _attr.trim();
				}
			}
			jQuery( _options ).attr( _optionsToCheck[i], _attr );
		}
		
		var strForm = '';
		strForm = _options.form.template;
		strForm = strForm
			.replace( /{formName}/gi, _options.form.name )
			.replace( /{formMethod}/gi, _options.form.method )
			.replace( /{formAction}/gi, _options.action )
			.replace( /{formTarget}/gi, _options.form.target )
			.replace( /{conteudo-area}/gi, _options.area )
			.replace( /{conteudo-data}/gi, _options.data )
			.replace( /{conteudo-titulo}/gi, _options.titulo )
			.replace( /{conteudo-chamada}/gi, _options.chamada )
			.replace( /{conteudo-integra}/gi, _options.integra );
		
		var $formCompleto = jQuery( strForm );
		jQuery( 'body' ).append( $formCompleto );
		var $form = jQuery( '#' + _options.form.name );
		
		var $this = jQuery( this );
		return $this.each(function() {
			var $$this = jQuery( this );
			var __href = _options.href;
			$$this.attr( 'href', __href ).bind( 'click', function( evento ) {
				evento.preventDefault();
				$form.trigger( 'submit' );
				return false;
			});
		});
		
	};
})(jQuery);